/**
 *
 * User: c3t
 * Date: 14-3-19
 * Time: 上午15:32
 */
define(function (require, exports, module) {
    var $ = require('js/lib/jquery');

    function showMenu() {
        var cObj = $("#cname");
        var cOffset = $("#cname").offset();
        $("#menuContent").css({left: cOffset.left + "px", top: cOffset.top + cObj.outerHeight() + "px"}).slideDown("fast");

        $("body").bind("mousedown", onBodyDown);
    }

    function onBodyDown(event) {
        if (!(event.target.id == "menuBtn" || event.target.id == "menuContent" || $(event.target).parents("#menuContent").length > 0)) {
            hideMenu();
        }
    }

    function hideMenu() {
        $("#menuContent").fadeOut("fast");
        $("body").unbind("mousedown", onBodyDown);
    }

    function beforeChoice(treeId, treeNode) {
        // 是父节点check为false
        var check = (treeNode && !treeNode.isParent);
        if (!check) {
            alert("不可添加父栏目");
        } else {
            $("#cname").val(treeNode.name);
            $("#cid").val(treeNode.id);
            hideMenu();
        }
    }

    /*    function choice(event,treeId,treeNode) {
     $("#cname").val(treeNode.name);
     hideMenu();
     }*/
    $("#cname").click(showMenu);

    $("#mytree").mytree(
        {
            callback: {
                beforeDblClick: beforeChoice
            }
        }
    );
    require('js/lib/core/jquery_ui')($);
    require('js/lib/core/jquery_ui_datepicker')($);
    require('js/lib/core/jquery_ui_date_zh')($);
    $("#publishDate").datepicker({
        dateFormat: "yy-mm-dd",//设置日期格式
        maxDate:0,//最大日期为1年后(2013-2-2具体日期)
        changeMonth:true,//可以选择一个月份
        changeYear:true//可以选择一个年份
    });

/*    require("js/lib/core/xeditor")($);
    $("#content").xheditor({tools:"full"});*/


    require("js/lib/core/jquery.cms.keyword.js")($);
    $("#keyword").keywordInput({
        as:{
            enable:true,
            url:"admin/topic/searchKeyword",
            minLength:2
        }
    });


});
